package f.admin.entity;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;

import net.sf.json.JSONObject;

public class DictionaryModule {

	public static final String TABLE_NAME = "t_dep_dict_modulel";
	
	private String id;
	private String name;
	private Timestamp createTime;
	
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public Date getCreateTime() {
		return createTime;
	}
	public void setCreateTime(Timestamp createTime) {
		this.createTime = createTime;
	}
	
	public String getJsonString() {
		JSONObject jsonObj = new JSONObject();
		Field[] fields = this.getClass().getDeclaredFields();
		for(int i = 0; i < fields.length; i++) {
			Field field = fields[i];
			if(field.getName().equals("TABLE_NAME")) {
				continue;
			}
			field.setAccessible(true);
			try {
				if(field.getType().equals(Timestamp.class)) {
					String fieldName = field.getName();
					String methodName = "get" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1, fieldName.length());
					Method method = this.getClass().getMethod(methodName);
					Timestamp time = (Timestamp) method.invoke(this);
					SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
					String dateValue = format.format(time);
					jsonObj.put(field.getName(), dateValue);
				} else {
					jsonObj.put(field.getName(), field.get(this));
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return jsonObj.toString();
	}
}
